<template>
  <div class="article-comment">
    <!-- 全部评论 -->
    <van-sticky offset-top="11.73333vw">
      <div class="title van-hairline--bottom">
        <span>全部评论 ({{article.comm_count}})</span>
        <span>{{article.like_count}} 点赞</span>
      </div>
    </van-sticky>

    <!-- 评论列表 -->
    <div class="list">
    <van-list v-model="loading" :finished="finished" finished-text="没有评论了" @load="onLoad">
      <div class="item van-hairline--bottom" v-for="item in comment" :key="item.com_id">
        <van-image round width="10vw" height="10vw" :src="item.aut_photo"/>
        <div class="info">
          <p>
            <span class="name">{{item.aut_name}}<i>0</i></span>
            <span class="zan">{{item.like_count}}<van-icon name="like2" /></span>
          </p>
          <p class="cont">{{item.content}}！</p>
          <p>
            <span class="reply">{{item.reply_count}}回复 <i class="van-icon van-icon-arrow"></i></span>
            <span class="time">{{item.pubdate|relaticeTime}}</span>
          </p>
        </div>
      </div>
    </van-list>
    </div>
    <!-- 底部工具 -->
    <div class="footer van-hairline--top">
      <div class="input"><i class="van-icon van-icon-edit"></i></div>
      <div class="btn"><van-icon name="chat-o"></van-icon><p>评论</p>
           <i v-if="article.comm_count" class="active">{{article.comm_count}}</i>
      </div>
      <div class="btn">
        <van-icon name="good-job-o" :color="article.attitude===1?'orange':''"></van-icon><p>点赞</p></div>
      <div class="btn"><van-icon name="like-o"></van-icon><p>收藏</p></div>
      <div class="btn"><van-icon name="share-o"></van-icon><p>分享</p></div>
    </div>
  </div>
</template>
<script>
import { getComment } from '@/api/article'
export default {
  name: 'ArticleComment',
  data () {
    return {
      comment: {},
      loading: false,
      finished: false,
      offset: null
    }
  },
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 滑到低会触发的 评论列表
    async onLoad () {
      // console.log('加载评论')
      // console.log(this.article.art_id)
      const res = await getComment({
        type: 'a',
        source: this.article.art_id
      })

      if (res.data.end_id === res.data.last_id) {
        // 数据全部加载完成
        this.finished = true
      }
      // console.log(res)
      // 追加评论数据
      this.comment.push(...res.data.data.results)
      // 结束加载状态
      this.loading = false
    }
  }
}
</script>
<style scoped lang="less">
   .footer {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 50px;
    background: #fff;
    display: flex;
    width: 100%;
    align-items: center;
    .input {
      margin-left: 10px;
      width: 200px;
      height: 34px;
      background:#f7f8fa;
      border-radius: 17px;
      line-height: 36px;
      padding-left: 10px;
      .van-icon {
        color: #999;
      }
    }
    .btn {
      flex: 1;
      text-align: center;
      position: relative;
      display:flex;
      flex-direction: column;
      justify-content: space-evenly;
      p {
        margin: 0;
        font-size: 10px;
      }
      .van-icon {
        font-size: 18px;

      }
      .active {
        height: 16px;
        min-width: 16px;
        padding: 0 3px;
        background: #fc6627;
        color: #fff;
        font-size: 10px;
        position: absolute;
        right: 0;
        top: -8px;
        line-height: 16px;
        border-radius: 8px;
        font-style: normal;
      }
    }
  }
.article-comment {
  .title {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    background: #fff;
    span {
      font-size: 16px;
      &:last-child {
        color: #ccc;
        font-size: 14px;
      }
    }
  }
  .list {
    padding: 0 16px;
    .item {
      display: flex;
      padding: 10px 0;
      .info {
        padding-left: 10px;
        flex: 1;
        p {
          margin: 0;
          .name {
            font-size: 16px;
          }
          .zan {
            font-size: 14px;
            float: right;
            color: #999;
            .van-icon {
              font-size: 12px;
              position: relative;
              top: -1px;
            }
          }
          &.cont {
            font-size: 14px;
            color: #666;
            padding: 10px 0;
            word-break: break-all;
            padding-right: 40px;
          }
          .reply {
            min-width: 60px;
            height: 24px;
            text-align: center;
            line-height: 28px;
            font-size: 12px;
            background: gray;
            display: inline-block;
            border-radius: 14px;
            color: #666;
            .van-icon {
              position: relative;
              top: 1px;
            }
          }
          .time {
            font-size: 12px;
            color: #999;
            margin-left: 10px;
          }
        }
      }
    }
  }
}
</style>
